package com.api.oa.config;

import com.easemob.im.server.EMProperties;
import com.easemob.im.server.EMService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;


@Configuration
public class InterceptorConfig extends WebMvcConfigurationSupport {

    @Autowired
    private TokenHandler tokenHandler;


    @Override
    public void addInterceptors(InterceptorRegistry registry) {

        registry.addInterceptor(tokenHandler).addPathPatterns("/yq/**","/oa/**")
                .excludePathPatterns(Arrays.asList("/file/**","yq/yQPatient/addBatch",
                        "yq/yQInsEntity/addBatch","yq/yQMedCare/addBatch","/yq/yQWork/play/**","yq/yQConfigAgreement/**"));
    }

    @Override
    protected void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/");
    }



    @Bean
    public EMService service() {

        EMProperties properties = EMProperties.builder()
                .setAppkey("1163220307110014#jiaozhou")
                .setClientId("YXA6F5vtc-EiQh6ngaHs8K7hQg")
                .setClientSecret("YXA6fSh2zPmwN--l8RYEuYrKJj3hec4")
                .build();

        return new EMService(properties);
    }
}
